home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / optivc32 / mdstd.h < prev    next >
C/C++ Source or Header  |  1999-03-06  |  59KB  |  1,086 lines

  1. /*  MDstd.h
  2.  
  3.   matrix management functions:
  4.   manipulations on matrices of data type "double"
  5.   (double-precision real numbers)
  6.  
  7.   Copyright (c) 1996-1999 by Martin Sander
  8.   All Rights Reserved.
  9. */
  10.  
  11. #if !defined( __MDSTD_H )
  12. #define __MDSTD_H
  13. #if !defined( __MATLIB_H )
  14. #include <MatLib.h>
  15. #endif
  16. #if !defined( __VDSTD_H )
  17. #include <VDstd.h>
  18. #endif
  19. #if !defined( __VDMATH_H )
  20. #include <VDmath.h>
  21. #endif
  22.  
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26.  
  27. /*************   Dynamic Generation of Matrices   ************************/
  28.  
  29. dMatrix __vf  MD_matrix(  unsigned ht, unsigned len );
  30. dMatrix __vf  MD_matrix0( unsigned ht, unsigned len );
  31.     /*  notice that, in the memory model HUGE,
  32.         neither len nor ht may exceed 4095            */
  33.  
  34. /***************************************************************************
  35.  *  The following definitions ensure compatibility between dynamically     *
  36.  *  and statically allocated matrices. The definitions are somewhat        *
  37.  *  cumbersome, but the result for you is that you need not care about     *
  38.  *  the differences between the two types.                                 *
  39.  *  (Internally, the address of the first element of any matrix is needed; *
  40.  *  the expression "MA[0]" is evaluated in a different way for both types, *
  41.  *  but yields in either case the correct address to be passed to the      *
  42.  *  function you wish to call.)                                            *
  43.  *  Only in the rare case that you need to pass the address of one of      *
  44.  *  these functions as an argument to another function, you have to use    *
  45.  *  the actual run-time functions defined further below. Be careful with   *
  46.  *  this: future development of compilers may allow us to avoid this un-   *
  47.  *  handy scheme of macros. So future versions of MatrixLib may no longer  *
  48.  *  use these run-time names.                                              *
  49.  ***************************************************************************/
  50.  
  51.  
  52. /***  Addressing single elements of dynamically allocated matrices: ******
  53.      These two functions are for compatibility with Pascal
  54.      (where elements of dynamically allocated matrices are not directly
  55.      accessible), and for getting around the pointer arithmetics bug in
  56.      some versions of Borland C++.                                         */
  57.  
  58. #define MD_Pelement( MA, ht, len, m, n ) MDPelement( MA[0], ht, len, m, n )
  59.                      /* returns a pointer to MA[m][n]. */
  60. #define MD_element( MA, ht, len, m, n ) *MDPelement( MA[0], ht, len, m, n )
  61.                      /* dereferenced pointer */
  62.  
  63.  /****************  Initialization  ***************************************
  64.  
  65.     To initialize all elements of a matrix with the same value,
  66.     or to perform arithmetic operations on all elements simultaneously,
  67.     refer to the functions of VectorLib, declared in <VDstd.h>, <VDmath.h>.
  68.     In order to use the VectorLib functions, utilize the feature that
  69.     the whole matrix occupies one contiguous area in memory: pass the
  70.     address of the first row to the desired vector function, the size
  71.     of the "vector" being ht * len.
  72.     For example, initialize all elements of the matrix MA with 1.0
  73.     (this is *NOT* the identity matrix)  by calling
  74.         VD_equ1( MA[0], ht * len );
  75. */
  76.  
  77. #define MD_equ0( MA, ht, len )            VD_equ0( MA[0], ((ui)ht)*len )
  78. #define MD_equ1( MA, len )                MDequ1( MA[0], len )
  79.                        /* this is the identity matrix */
  80. #define MD_outerprod( MA, X, Y, ht, len ) MDouterprod( MA[0], X, Y, ht, len )
  81.                        /* sizX=ht, sizY=len */
  82. #define MD_Row_equC( MA, ht, len, iRow, C ) \
  83.                                         MDRow_equC( MA[0], ht, len, iRow, C )
  84. #define MD_Col_equC( MA, ht, len, iCol, C ) \
  85.                                         MDCol_equC( MA[0], ht, len, iCol, C )
  86. #define MD_Dia_equC( MA, len, C )       MDDia_equC( MA[0], len, C )
  87.  
  88. #define MD_Row_equV( MA, ht, len, iRow, X ) \
  89.                                         MDRow_equV( MA[0], ht, len, iRow, X )
  90. #define MD_Col_equV( MA, ht, len, iCol, X ) \
  91.                                         MDCol_equV( MA[0], ht, len, iCol, X )
  92. #define MD_Dia_equV( MA, len, X )       MDDia_equV( MA[0], len, X )
  93.  
  94. #define MD_equM( MB, MA, ht, len )  VD_equV( MB[0], MA[0], (ui)(ht)*(len) )
  95.  
  96. #define MD_UequL( MA, len ) MDUequL( MA[0], len )
  97. #define MD_LequU( MA, len ) MDLequU( MA[0], len )
  98.          /* copy lower-diagonal elements into upper-diagonal
  99.            (or vice versa) by index-reflection, so as to
  100.            get a symmetric matrix    */
  101.  
  102.             /* data-type conversions:  */
  103. #define M_DtoF( MF, MD, ht, len ) V_DtoF( MF[0], MD[0], ((ui)ht)*len )
  104. #define M_FtoD( MD, MF, ht, len ) V_FtoD( MD[0], MF[0], ((ui)ht)*len )
  105. #define M_EtoD( MD, ME, ht, len ) V_EtoD( MD[0], ME[0], ((ui)ht)*len )
  106. #define M_DtoE( ME, MD, ht, len ) V_DtoE( ME[0], MD[0], ((ui)ht)*len )
  107.  
  108.             /* suitable windows for MF_spectrum: */
  109. #define MD_Hanning( MA, ht, len )  MDHanning( MA[0], ht, len )
  110. #define MD_Parzen( MA, ht, len )   MDParzen( MA[0], ht, len )
  111. #define MD_Welch( MA, ht, len )    MDWelch( MA[0], ht, len )
  112.  
  113. /********  Extracting a submatrix and copying a submatrix back  *********/
  114.  
  115. #define MD_submatrix( MSub, subHt, subLen, \
  116.                       MSrce, srceHt, srceLen, \
  117.                       firstRowInCol, sampInCol, firstColInRow, sampInRow ) \
  118.                MDsubmatrix(  MSub[0], subHt, subLen, \
  119.                              MSrce[0], srceHt, srceLen, \
  120.                              firstRowInCol, sampInCol, firstColInRow, sampInRow )
  121.  
  122. #define MD_submatrix_equM( MDest, destHt, destLen, \
  123.                            firstRowInCol, sampInCol, firstColInRow, sampInRow, \
  124.                            MSrce, srceHt, srceLen ) \
  125.                MDsubmatrix_equM(  MDest[0], destHt, destLen, \
  126.                              firstRowInCol, sampInCol, firstColInRow, sampInRow, \
  127.                              MSrce[0], srceHt, srceLen )
  128.  
  129. /*****   Extracting a single row or a single column or the diagonal  ******
  130.  *       and storing it into a vector                                     */
  131.  
  132. #define MD_Row_extract( Y, MA, ht, len, iRow ) \
  133.                                      MDRow_extract( Y, MA[0], ht, len, iRow )
  134. #define MD_Col_extract( Y, MA, ht, len, iCol ) \
  135.                                      MDCol_extract( Y, MA[0], ht, len, iCol )
  136. #define MD_Dia_extract( Y, MA, len ) MDDia_extract( Y, MA[0], len )
  137.  
  138.  
  139. /*****************    Basic arithmetic operations *********************
  140.                       performed on one single row,
  141.                       or one single column of any matrix,
  142.                       or on the diagonal of a square matrix
  143.  
  144.     Note: In contrast to the analogous VectorLib functions, the operations
  145.     are performed in-place, i.e. the input matrix itself is changed  */
  146.  
  147. #define MD_Row_addC( MA, ht, len, iRow, C ) \
  148.                                      MDRow_addC( MA[0], ht, len, iRow, C )
  149. #define MD_Col_addC( MA, ht, len, iCol, C ) \
  150.                                      MDCol_addC( MA[0], ht, len, iCol, C )
  151. #define MD_Dia_addC( MA, len, C )    MDDia_addC( MA[0], len, C )
  152.  
  153. #define MD_Row_addV( MA, ht, len, iRow, X ) \
  154.                                      MDRow_addV( MA[0], ht, len, iRow, X )
  155. #define MD_Col_addV( MA, ht, len, iCol, X ) \
  156.                                      MDCol_addV( MA[0], ht, len, iCol, X )
  157. #define MD_Dia_addV( MA, len, X )    MDDia_addV( MA[0], len, X )
  158.  
  159. #define MD_Row_subC( MA, ht, len, iRow, C ) \
  160.                                      MDRow_addC( MA[0], ht, len, iRow, (-C) )
  161. #define MD_Col_subC( MA, ht, len, iCol, C ) \
  162.                                      MDCol_addC( MA[0], ht, len, iCol, (-C) )
  163. #define MD_Dia_subC( MA, len, C )    MDDia_addC( MA[0], len, (-C) )
  164.  
  165. #define MD_Row_subV( MA, ht, len, iRow, X ) \
  166.                                      MDRow_subV( MA[0], ht, len, iRow, X )
  167. #define MD_Col_subV( MA, ht, len, iCol, X ) \
  168.                                      MDCol_subV( MA[0], ht, len, iCol, X )
  169. #define MD_D